using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExtraClub.Domain.Entity;
using System.Collections.Specialized;
using ExtraClub.Domain.Forms;
using ExtraClub.Domain.Framework;

namespace ExtraClub.Domain {
    public class BaseForm : BaseUserControl {
        protected string EntityId { get; set; }

        protected string WS {
            get {
                return string.Format("ExtraClub.Web.Forms.Service.{0}", this.TemplateControl.AppRelativeVirtualPath.ToLower().Replace("/module.ascx", "").Replace("~/modules/forms/", ""));
                ;
            }
        }


        protected override void OnInit(EventArgs e) {
            base.OnInit(e);
        }
        protected virtual void LoadAssets() {
            ResisterCSSFile("assets/inputex/lib/yui/assets/skins/sam/skin.css");
            ResisterCSSFile("assets/inputex/css/inputEx.css");

            ResisterJSFile("assets/inputex/lib/yui/yahoo/yahoo.js");
            ResisterJSFile("assets/inputex/lib/yui/dom/dom.js");
            ResisterJSFile("assets/inputex/lib/yui/event/event-min.js");
            ResisterJSFile("assets/inputex/lib/yui/container/container-min.js");
            ResisterJSFile("assets/inputex/lib/yui/calendar/calendar-min.js");

            ResisterJSFile("assets/inputex/lib/yui/element/element.js");
            ResisterJSFile("assets/inputex/lib/yui/menu/menu-min.js");
            ResisterJSFile("assets/inputex/lib/yui/button/button-min.js");
            // ResisterJSFile("assets/inputex/lib/yui/editor/editor-min.js"); CONFLICTS WITH MOOTOOLS

            ResisterJSFile("assets/inputex/js/inputex.js");
            ResisterJSFile("assets/inputex/js/Field.js");
            ResisterJSFile("assets/inputex/js/fields/StringField.js");
            ResisterJSFile("assets/inputex/js/fields/EmailField.js");
            ResisterJSFile("assets/inputex/js/fields/CombineField.js");
            ResisterJSFile("assets/inputex/js/fields/SelectField.js");
            ResisterJSFile("assets/inputex/js/fields/Textarea.js");
            ResisterJSFile("assets/inputex/js/fields/NumberField.js");
            ResisterJSFile("assets/inputex/js/fields/IntegerField.js");
            ResisterJSFile("assets/inputex/js/fields/HiddenField.js");
            ResisterJSFile("assets/inputex/js/fields/DateField.js");
            ResisterJSFile("assets/inputex/js/fields/IntegerField.js");
            ResisterJSFile("assets/inputex/js/fields/CheckBox.js");
            ResisterJSFile("assets/inputex/js/ext/BirthdateField/BirthdateField.js");
            ResisterJSFile("assets/inputex/js/ext/MyDateSplitField.js");
            ResisterJSFile("assets/inputex/js/Group.js");
            ResisterJSFile("assets/inputex/js/Form.js");

            ResisterJSFile("fckeditor/fckeditor.js");

            ResisterJSFile("assets/js/Form.js");
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            UISelectOptions = new IndexedProperty<string, List<string>>(GetUISelectOptionsProperty);
            UISelectValues = new IndexedProperty<string, List<string>>(GetUISelectValuesProperty);

            ResisterWSFile(this.TemplateControl.AppRelativeVirtualPath.Replace("~/", "").Replace("ascx", "asmx"));
            LoadAssets();

            if (Request.QueryString.Count > 0 && Request.QueryString["id"] != null) {
                EntityId = Request.QueryString["id"];
            }
        }

        protected virtual string SetFields() { return ""; }

        protected void AddHiddenFieldes(ref FieldCollection fs, string EntityId) {

            new Field(FieldType.Hidden, Constants.FormField.Command, f =>
            {
                f.Value = CurrentCommand.ToString();
            }, fs);

            new Field(FieldType.Hidden, Constants.FormField.EntityId, f =>
            {
                f.Value = EntityId;
            }, fs);

            new Field(FieldType.Hidden, Constants.FormField.ReturnUrl, f =>
            {
                f.Value = WebUtils.SetCommandUrl(ECommand.None);
            }, fs);

            new Field(FieldType.Hidden,Constants.FormField.Language, f =>
            {
                f.Value = SiteContext.Current.Language;
            }, fs);

            new Field(FieldType.Hidden,Constants.FormField.PageUrl, f =>
            {
                f.Value = SiteContext.Current.Page.Url;
            }, fs);
        }
    }
}
